home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q0429.dms / q0429.adf / libray / libsurf / atmosphere.c next >
C/C++ Source or Header  |  1991-08-08  |  2KB  |  92 lines

  1. /*
  2.  * atmosphere.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: atmosphere.c,v 4.0 91/07/17 14:40:02 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    atmosphere.c,v $
  19.  * Revision 4.0  91/07/17  14:40:02  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "atmosphere.h"
  24.  
  25. Atmosphere *
  26. AtmosCreate(data, method)
  27. char *data;
  28. void (*method)();
  29. {
  30.     Atmosphere *ef;
  31.  
  32.     ef = (Atmosphere *)Malloc(sizeof(Atmosphere));
  33.     ef->data = data;
  34.     ef->method = method;
  35.     ef->next = (Atmosphere *)0;
  36.     return ef;
  37. }
  38.  
  39. Atmosphere *
  40. AtmosphereCopy(atmos)
  41. Atmosphere *atmos;
  42. {
  43.     Atmosphere *res;
  44.  
  45.     if (atmos == (Atmosphere *)NULL)
  46.         return (Atmosphere *)NULL;
  47.     res = AtmosCreate(atmos->data, atmos->method);
  48.     res->next = AtmosphereCopy(atmos->next);
  49.     return res;
  50. }
  51.  
  52. Medium *
  53. MediumPush(index, statten, media)
  54. Float index, statten;
  55. Medium *media;
  56. {
  57.     Medium *new;
  58.  
  59.     new = (Medium *)Malloc(sizeof(Medium));
  60.     new->index = index;
  61.     new->statten = statten;
  62.     new->next = media;
  63.  
  64.     return new;
  65. }
  66.  
  67. void
  68. Atmospherics(effects, ray, dist, pos, color)
  69. Atmosphere *effects;
  70. Ray *ray;
  71. Float dist;
  72. Vector *pos;
  73. Color *color;
  74. {
  75.     Atmosphere *etmp;
  76.  
  77.     for (etmp = effects; etmp; etmp = etmp->next)
  78.         (*etmp->method)(etmp->data, ray, pos, dist, color);
  79. }
  80.  
  81. Float
  82. ExpAtten(dist, trans)
  83. Float dist, trans;
  84. {
  85.     Float atten;
  86.  
  87.     if (trans < EPSILON)
  88.         return 0.;
  89.     atten = LNHALF * dist / trans;
  90.     return (atten < -10. ? 0. : exp(atten));
  91. }
  92.